#!/usr/bin/python
# -*- coding: utf-8 -*-

'''
Introduction to Programming in Java - An Interdisciplinapos_y Approach

All book programs ported to Python by
Scott C. King (revisionx at {gee}ma1l <dot> c0m).

All program examples pass Pylint with a perfect 10.00 score.
Pylint:  http://www.pylint.org/


Program 1.5.6 - Bouncing ball

Syntax:
python bouncingball.py


Notes:
sys is a required import here in order to use stdin/sys.argv.
https://docs.python.org/2/tutorial/stdlib.html

Turtle is a required import here for a comparable Python module.
https://docs.python.org/2/library/turtle.html

Turtle is, well, considerably slower than the StdDraw module in Java.

'''

import turtle
import time


def main():
    ''' Bouncing ball from Java implemented in turtle. '''

    my_turtle = turtle.Turtle()
    my_screen = turtle.Screen()
    my_screen.setworldcoordinates(-1.0, -1.0, 1.0, 1.0)
    my_screen.title('Bouncing Ball')
    my_turtle.hideturtle()
    my_turtle.speed(0)

    pos_x = .480
    pos_y = .860
    vel_x = .015
    vel_y = .023
    radius = .05

    while True:
        if abs(pos_x + vel_x) + radius > 1.0:
            vel_x = -vel_x
        if abs(pos_y + vel_y) + radius > 1.0:
            vel_y = -vel_y
        pos_x += vel_x
        pos_y += vel_y

        my_turtle.setposition(pos_x, pos_y)
        my_turtle.fill(True)
        my_turtle.circle(radius)
        my_turtle.fill(False)
        time.sleep(.010)
        my_screen.clear()


if __name__ == '__main__':
    main()
